#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;

int a[200010];
int n, ans;

void dfs(int step, int res, int last_r, int last_b) {
    if (step > n) {
        ans = max(ans, res);
        return ;
    }
    if (last_r == -1) dfs(step + 1, res, step, last_b);
    else dfs(step + 1, res + (a[last_r] == a[step] ? a[last_r] : 0), step, last_b);
    if (last_b == -1) dfs(step + 1, res, last_r, step);
    else dfs(step + 1, res + (a[last_b] == a[step] ? a[last_b] : 0), last_r, step);
}



int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    int t;
    cin >> t;
    while (t--) {
        cin >> n;
        ans = -1;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        ans = 0;
        dfs(1, 0, -1, -1);
        cout << ans << endl;
    }
    return 0;
}
